
function colorRGBtoHex(color) {
  let rgb = color.split(',')
  let r = parseInt(rgb[0].split('(')[1])
  let g = parseInt(rgb[1])
  let b = parseInt(rgb[2].split(')')[0])
  let hex = '#' + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1)
  return hex
}

function colorHextoRGB(color, opcity = '0.7') {
  if (typeof color !== 'string') {
    return
  }
  const rgba = []
  let temp = ''
  for (let i = 0; i < color.length; i++) {
    if (color[i] === '#') {
      continue
    }
    temp += color[i]
    if (temp.length === 2) {
      temp = Number.parseInt(temp, 16)
      rgba.push(temp.toString(10))
      temp = ''
    }
  }
  rgba.push(opcity)
  return '(' + rgba.join(',') + ')'
}

export default {
  colorRGBtoHex,
  colorHextoRGB

}
